package com.wq.myspring.beantest;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * @PackageName: com.wq.myspring
 * @ClassName MyTest3
 * @Description: TODO
 * @Author Wenqiang
 * @Date 2021/07/16 21:45
 * @Version V1.0
 */
public class MyTest3 {
	public static void main(String[] args) {
		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
		Car car = context.getBean("car", Car.class);
		Car car1 = context.getBean("car1", Car.class);
		System.out.println(car);
		System.out.println(car1);
	}
}


class Config {

	@Bean
	public Car car() {
		Car car = new Car();
		car.setName("保时捷");
		return car;
	}

	@Bean
	public Car car1() {
		Car car = new Car();
		car.setName("法拉利");
		return car;
	}



}

class Car {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String toString() {
		return  "[" + hashCode() + "] Car{" +
				"name='" + name + '\'' +
				'}';
	}
}
